<template>
	<view>
		<view class="pt-20 pl-20 pr-20">
			<view class="bg-white flex space-between items-center bg-white p-30 border-radius">
				<view class="flex items-center">
					<image v-if="companyInfo.logo" :src="companyInfo.logo" mode="" style="width: 70rpx;height: 70rpx;border-radius: 50%;">
					</image>
					<image v-if="!companyInfo.logo" src="@/static/images/company.png" mode="" style="width: 70rpx;height: 70rpx;border-radius: 50%;">
					</image>
					<view class=" ml-20">
						<view class="font-24">{{companyInfo.name}}</view>
						<view class="font-22 font-grey mt-10">{{companyInfo.companyProfession}} | {{companyInfo.scale}}人
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="pt-20 pl-20 pr-20">
			<view class="bg-white p-30 border-radius">
				<view class="font-26">公司地址</view>
				<view class="flex items-center space-between mt-20">
					<view class="font-22 font-grey font-no-wrap" style="width: 60vw;">{{companyInfo.city}}{{companyInfo.address}}</view>
					<view class="border-g font-g pt-10 pb-10 pl-20 pr-20 border-radius font-22" @click="goMap">导航</view>
				</view>
			</view>
		</view>
		<view class="pt-20 pl-20 pr-20">
			<view class="bg-white p-30 border-radius">
				<view class="font-26">公司介绍</view>
				<view class="flex items-center space-between mt-20 font-24 font-grey">
					<rich-text :nodes="companyInfo.intro"></rich-text>
				</view>
			</view>
		</view>
		<view class="pt-40 pl-40 pr-20">在招职位</view>
		<view class="pl-30 pr-30 pt-30" v-for="(item, index) in inviteList" :key="index"
			@click="$goRoute.goUrl('/pages/lists/details?id='+item.id)">
			<view class="bg-white pl-20 pr-20 pt-30 pb-30 border-radius">
				<view class="flex space-between flex-align-end">
					<view class="font-bold font-30">{{item.name}}</view>
					<view class="font-26 font-g font-bold">{{item.payLow}}-{{item.payHigh}}</view>
				</view>
				<view class="flex font-26 mt-20">
					<view>{{item.companyId_dictText}}</view>
					<!-- <view class="ml-40">2000-5000人</view> -->
				</view>
				<view class="flex font-22 mt-10" style="color: #686E6E;">
					<view class="pt-10 pb-10 pl-30 pr-30">{{item.jobNature}}</view>
					<view class="pt-10 pb-10 pl-30 pr-30">{{item.peopleNum}}人</view>
					<view class="pt-10 pb-10 pl-30 pr-30">{{item.education_dictText}}</view>
					<view class="pt-10 pb-10 pl-30 pr-30">{{item.experience}}</view>
				</view>
				<view class="flex space-between items-center mt-10">
					<view class="flex items-center">
						<image src="../../static/images/avatar.png" mode=""
							style="width: 50rpx;height: 50rpx;border-radius: 50%;"></image>
						<view class="font-24 ml-10">{{item.hruserId_dictText}}</view>
					</view>
					<view class="font-24">{{item.city}}</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		list
	} from '../../api/invite';
	import {
		queryById as queryByIdCompany
	} from '../../api/company.js';
	import {
		loadOne
	} from '../../api/common.js';
	export default {
		data() {
			return {
				id: 0,
				companyInfo: {},
				companyProfession: {},
				latitude: '',
				longitude: '',
				pageNo: 1,
				pageSize: 10,
				inviteList: []
			};
		},
		onLoad(options) {
			this.id = options.id
			this.getCompany()
		},
		onShareAppMessage(res) {
			if (res.from === 'button') { // 来自页面内分享按钮
				console.log(res.target)
			}
			return {
				title: '河口人才招聘小程序',
				path: '/pages/company/details'
			}
		},
		onReachBottom() {
			this.getInviteList()
		},
		methods: {
			getInviteList() {
				uni.showLoading({
					title: '加载中'
				})
				list({
					pageSize: this.pageSize,
					pageNo: this.pageNo,
					companyId: this.companyInfo.id
				}).then(res => {
					if (this.pageNo === 1) {
						this.inviteList = res.result.records
					} else {
						this.inviteList.push(...res.result.records)
					}
					this.pageNo += 1
					uni.hideLoading()
				})
			},
			loadCategory(field) {
				loadOne({
					field: 'id',
					val: field
				}).then(res => {
					this.companyProfession = res.result
				})
			},
			getCompany() {
				queryByIdCompany({
					id: this.id
				}).then(res => {
					this.companyInfo = res.result
					this.loadCategory(res.result.companyProfession)
					this.latitude = res.result.latitude
					this.longitude = res.result.longitude
					this.getInviteList()
				})
			},
			goMap() {
				const _this = this
				uni.authorize({
					scope: 'scope.userLocation',
					success() {
						uni.getLocation({
							type: 'gcj02', //返回可以用于uni.openLocation的经纬度
							success: function(res) {
								console.log(res)
								const latitude = res.latitude;
								const longitude = res.longitude;
								uni.openLocation({
									latitude: parseFloat(_this.latitude),
									longitude: parseFloat(_this.longitude),
									success: function() {
										console.log('success');
									},
									fail:function(err){
										console.log(err)
									}
								});
							}
						});
					},
					fail() {}
				})
			}
		}
	}
</script>

<style lang="less">
	page {
		background-color: #f6f6f6;
	}
</style>
